package cn.jroid.demo.util;

import java.util.Calendar;
import java.util.Date;

public class BaseUtil {
	public static String getTimeDiff(Date date) { 
        Calendar cal = Calendar.getInstance(); 
        long diff = 0; 
        Date dnow = cal.getTime(); 
        String str = ""; 
        diff = dnow.getTime() - date.getTime(); 
          
        if  (diff > 2592000000L) {//30 * 24 * 60 * 60 * 1000=2592000000 毫秒 
            str="1个月前"; 
        } else if  (diff > 1814400000) {//21 * 24 * 60 * 60 * 1000=1814400000 毫秒 
            str="3周前"; 
        } else if  (diff > 1209600000) {//14 * 24 * 60 * 60 * 1000=1209600000 毫秒 
            str="2周前"; 
        } else if  (diff > 604800000) {//7 * 24 * 60 * 60 * 1000=604800000 毫秒 
            str="1周前"; 
        } else if (diff > 86400000) {    //24 * 60 * 60 * 1000=86400000 毫秒 
            //System.out.println("X天前"); 
            str=(int)Math.floor(diff/86400000f) + "天前"; 
        } else if (diff > 18000000 ) {//5 * 60 * 60 * 1000=18000000 毫秒 
            //System.out.println("X小时前"); 
            str=(int)Math.floor(diff/18000000f) + "小时前"; 
        } else if (diff > 60000) {//1 * 60 * 1000=60000 毫秒 
            //System.out.println("X分钟前"); 
            str=(int)Math.floor(diff/60000) +"分钟前"; 
        }else{ 
            str=(int)Math.floor(diff/1000) +"秒前"; 
        } 
        return str; 
    } 

}
